<?php

namespace app\payqr\model;

use app\BaseModel;

class CardJob extends BaseModel
{
    //定义表名
    protected $name = 'longbing_card_job';

    /**
     * @Purpose: 职务列表
     *
     * @Author:
     *
     * @Return: mixed 查询返回值（结果集对象）
     */
     public function getlist($where,$page,$limit){
         $data = $this->where($where)->order( 'top', 'desc' )->paginate([ 'list_rows' => $limit, 'page' => $page ])->toArray();
         $data['data'] = handleTimes($data['data'], 'create_time', 'Y-m-d H:i:s' );
         return $data;
     }
    /**
     * @Purpose: 根据员工获取工具列表
     * @Return: mixed 查询返回值（结果集对象）
     */
    public function getListByUser ( $card_id = 0, $uniacid )
    {
        $list = self::where( [ [ 'uniacid', '=', $uniacid ], [ 'status', '=', 1 ] ] )
                    ->field( [ 'id', 'name' ] )
                    ->order( 'top', 'asc' )
                    ->select()
                    ->toArray();

        if ( !$list )
        {
            $list = $this->initCardJob( $uniacid );
        }

        foreach ( $list as $index => $item )
        {
            $list[ $index ][ 'selected' ] = 0;
            if ( isset( $item[ 'id' ] ) && $item[ 'id' ] == $card_id )
            {
                $list[ $index ][ 'selected' ] = 1;
            }
        }

        return $list;
    }

    /**
     * @Purpose: 初始化名片样式
     *
     * @Author: zzf
     *
     * @Return: mixed 查询返回值（结果集对象）
     */
    public function initCardJob ( $uniacid )
    {
        $data   = [ [ 'name' => '首席服务官', 'uniacid' => $uniacid ] ];
        $result = self::createRows( $data );
        return $result->toArray();
    }
    public function getNameinfo($where){
        return $this->where($where)->find();
    }
}